package com.itheima.api.generic.demo01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GenericDemo01 {

    public static void main(String[] args) {

        Collection col = new ArrayList();

        col.add("hello");
        col.add("world");
        col.add("java");

        //迭代器
        Iterator iterator = col.iterator();

        while(iterator.hasNext()){
            Object next = iterator.next();
            System.out.println(next);
        }

        System.out.println("------------------------------------------------");

        //增强for循环
        for(Object o : col) {
            System.out.println(o);
        }

        System.out.println("------------------------------------------------");

        //forEach
        col.forEach(s -> System.out.println(s));

        System.out.println("------------------------------------------------");

        //普通for循环
        for (int i = 0; i < col.size(); i++) {
            Object o = ((ArrayList) col).get(i);
            System.out.println(o);
        }

    }

}
